//同步方法块
package 多线程;
class window implements Runnable{
    int ticket=10;
   A a=new A();
    public void run(){
        while (true) {            
          synchronized(a){
                if(ticket>0){
                try {
                    Thread.sleep(1000);
                } catch (Exception e) {
                }
                System.out.println(Thread.currentThread().getName()+"正在卖第"+ticket+"张票 ");
                ticket--;
            }
        }
          }
    }
}
class A{
    
}
public class 买票 {
    public static void main(String[] args) {
        window w=new window();
        Thread t1=new Thread(w);
        Thread t2=new Thread(w);
        Thread t3=new Thread(w);
        t1.start();
        t2.start();
        t3.start();
        t1.setName("窗口一");
        t2.setName("窗口二");
        t3.setName("窗口三");

    }
    
}
